(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.category.cate.cateDeleteController', deleteController);
	deleteController.$inject = [ '$scope', 'Constants', 'modalService', 'layoutConfig', 'validatorConfig', 'gridService', 'authService', 'categoryService' ];
	function deleteController($scope, Constants, modalService, layoutConfig, validatorConfig, gridService, authService, categoryService) {
		var ctrl = this, categoryInfo = $scope.$stateParams.params;
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.limitCategory = {};
		ctrl.init = function() {
			var params = {
					limitCatId : categoryInfo.id || categoryInfo.limitCatId
			};
			authService.delete(params).then(function(response) {
				ctrl.limitCategory = response.data || categoryInfo;
			});
		};
		
		ctrl.deleteSubmit = function() {
			modalService.openConfirmDialogs({
				'messages' : [ {msg : 'title.dialog.confirm.delete', args : [ctrl.limitCategory.limitCatName]} ],
				'btnCallback' : {
					'ok' : function(response) {
						authService.deleteSubmit(ctrl.limitCategory).then(deleteSuccessful, deleteFailed);
					}
				}
			});
		};
		
		function deleteSuccessful(response) {
			modalService.openAcknowledgeDialogs({
				'messages' : [ 'title.dialog.successful.delete' ],
				'btnCallback' : {
					'close' : function() {
						$scope.go('cda.category.cate');
					}
				},
				'redirections' : [ {
					'name' : 'title.infobar.workflow.list',
					'state' : 'cda.workflow.wfSetup.list',
					'params' : {}
				}, {
					'name' : 'title.infobar.category.list',
					'state' : 'cda.category.cate',
					'params' : {}
				}]
			});
		}

		function deleteFailed(response) {
			modalService.openErrorDialogs({
				'messages' : response.error
			});
		}
	}
})(angular);